/**
 * 转换详情
 */
define(['ldfw/core','art','text!tpl/transform/detail.tpl','comps/ajax','comps/session','ldfw/utils/format','ldfw/helper/formatHelper'],
    function(LDFW,art,tpl,ajax,session){
    var DetailView = LDFW.Container.extend({
        className:'panel',
        tpl:tpl,
        events:{
            'click .check-box':'toggleCheckStatus'
        },
        initialize:function(){
            const _this = this
            this.model.set('company_name',current_company)
        },
        loadData:function(){
            const _this = this
            let curr_user = session.getCurrentUser()
            this.model.set(curr_user)
            ajax.post('cpliL.3.105',{audit_no:this.audit_no})
                .success(function (resp) {
                    _this.model.set(resp.result)
                    _this.render()
                })
            //查询最新的审核信息
            ajax.post('cpliL.3.103',{audit_no:this.audit_no}).success(function (resp) {
                if (!_.isEmpty(resp.result)) {
                    var audit = resp.result[0]
                    _this.model.set('auth_date', format('date', 'yyyy年MM月dd日', audit.audit_date));
                    _this.render()
                }
            })
        },
        setAuditNo:function(audit_no){
            this.audit_no = audit_no
        },
        fileCompAddedHandler:function(comp){
            this.fileUploader =  comp
        },
        submitAudit:function(){
            let curr_user = session.getCurrentUser()
            let supplementary_material = this.fileUploader.getValue()
            let submit = true
            $('.check-box').each(function(){
                if(!$(this).hasClass('checked')){
                    $(this).addClass('error')
                    submit = false
                    return
                }
            })
            if(!submit){
                $.alert('对不起，您还没有对所有选项进行确认，不能提交申请')
            }else{
                ajax.post('cpliL.3.8',{
                    audit_type: 2,
                    change_type: curr_user.invester_class==='1'?1:2,
                    cust_type: curr_user.cust_type,
                    supplementary_material:supplementary_material
                }).success(function(resp){
                    if(!resp.resultCode){
                        $.toast('申请成功',1000,function(){
                            LDFW.navigate('transform')
                        })
                    }
                })
            }
        },
        toggleCheckStatus:function(event){
            let a = $(event.target)
            if(a.hasClass('checked')){
                a.removeClass('checked')
                a.find('i').addClass('icon-unchecked').removeClass('icon-checked')
            }else{
                a.addClass('checked').removeClass('error')
                a.find('i').removeClass('icon-unchecked').addClass('icon-checked')
            }
        }
    })
    return new DetailView()
})